<?php
	class PrivilegectrlModel extends Model
	{
		public function getAllPrivilegeList()
		{
			$list = $this -> select();
			$temp = array();
			$j = 0;
			foreach ($list as $i)
			{
				$temp[$j]['right'] = '<span id="pid'.(string)$j.'"></span>';
				$temp[$j++]['description'] = $i['description'];
			}
			return $temp;
		}
		public function getLevelFromID($ID)
		{
			$p = $this -> where("ID = ".(string)$ID) -> find();
			return $p['level'];
		}
		public function C($name)
		{
			/**
			 * This function is the Quick method of getting privilege level from name
			 * @var $name the privilege name
			 * @return level
			 */
			$p = $this -> where('name = "'.$name.'"') -> find();
			return $p['level'];
		}
		public function validatePermission($perID)
		{
			/**
			 * Validate permission
			 * 
			 * @var perID permissionID
			 * @return true or false. true means permitted.
			 */
			$l = $this -> getLevelFromID($perID);
			$result = true;
			if($_SESSION['PLevel'] < $l)
				$result = false;
			return $result;	
		}
	}
?>